/**
 * Bob.Ren
 * 2013-7-12
 */
package com.noqueue.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.noqueue.bean.Pager;
import com.noqueue.dao.CustomerQueueDao;
import com.noqueue.dao.QueueListPagerEateryDao;
import com.noqueue.entity.Customer;
import com.noqueue.entity.CustomerQueue;
import com.noqueue.entity.QueueListPagerEntity;
import com.noqueue.service.QueueService;

/**
 * @author Bob.Ren
 * @date 2013-7-12
 */
@Service
public class QueueServiceImpl implements QueueService {

	@Resource
	private QueueListPagerEateryDao queueListPagerEateryDao;
	@Resource
	private CustomerQueueDao customerQueueDao;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.noqueue.service.QueueService#loadQueueListPagerEntityByEateryId
	 * (java .lang.String)
	 */
	@Override
	public Pager loadQueueListPagerByEateryId(String id) {

		List<QueueListPagerEntity> entityList = queueListPagerEateryDao
				.loadEntityByEateryId(id);

		Pager pager = new Pager();

		pager.setList(entityList);
		pager.setTotalCount(entityList.size());
		pager.setPageCount(pager.getPageCount());

		return pager;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.noqueue.service.QueueService#settleAccount()
	 */
	@Override
	@Transactional
	public boolean settleAccount(String eateryId) {
		boolean isSuccess = false;

		Customer nextDineCustomer = queueListPagerEateryDao
				.getNextDineCustomerByEateryId(eateryId);
		Customer nextInformCustomer = queueListPagerEateryDao
				.getNextInformCustomerByEateryId(eateryId);

		if (sendMessageForDine(nextDineCustomer)
				&& sendMessageForReady(nextInformCustomer)) {
			CustomerQueue customerQueue = customerQueueDao
					.loadByEateryIdAndCusstomerId(eateryId,
							nextInformCustomer.getId());
			customerQueue.setIsInform(1);
			customerQueueDao.update(customerQueue);

			CustomerQueue customerQueue2 = customerQueueDao
					.loadByEateryIdAndCusstomerId(eateryId,
							nextDineCustomer.getId());
			customerQueue2.setIsDine(1);
			customerQueueDao.update(customerQueue2);

			isSuccess = true;
		}

		return isSuccess;
	}

	public boolean sendMessageForReady(Customer Customer) {

		return false;

	}

	public boolean sendMessageForDine(Customer Customer) {

		return false;

	}
}
